jQuery.noConflict();
    
// This is the function for the pagination plugin
function pageselectCallback(page_index, jq){
	var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
	jQuery('#Searchresult').empty().append(new_content);
	return false;
}

/** 
 * Initialisation function for pagination
 */
function initPagination() {
	// count entries inside the hidden content
	var num_entries = jQuery('#hiddenresult div.result').length;
	// Create content inside pagination element
	jQuery("#Pagination").pagination(num_entries, {
		callback: pageselectCallback,
		items_per_page:15 // Show only n item per page
	});
 }

 /**
  * fired on successful login
  */
function logged(profile) {
	jQuery.get('header_login_box.php', function (html) {
		jQuery('#login_action_container').html(html);
	});
}
          
		  
		  
/* WHEN DOCUMENT IS READY START */		  
jQuery(document).ready(function() {
	initPagination();

	jQuery('#login').fancybox({});

	jQuery('#login_form').bind("submit", function(e) {
		e.preventDefault();
		if (jQuery('#login_name').val().length < 1 || jQuery('#login_pass').val().length < 1) {
			jQuery('#login_error').show();
			jQuery.fancybox.resize();
			return false;
		}

		jQuery.fancybox.showActivity();

		jQuery.ajax({
			dataType: "json",
			type	: "POST",
			cache	: true,
			url		: "/ajax_login.php",
			data	: jQuery(this).serializeArray(),
			success: function(data) {
				if (data.status === 1) {//logged
					jQuery.fancybox(data.message);
					jQuery("#notice").slideDown();

					//fire logged event
					logged(data.profile);

					setTimeout(function () {
						jQuery.fancybox.close();
					}, 500);
				} else {//login failed
					jQuery.fancybox(data.message);
				}
			}
		});

		return false;
	});


});


/*
jQuery(document).ready(function() {
	jQuery('form[name=login_form]').submit(function() {
		
		jQuery('#errorConsole').hide();
		
		jQuery.post('/ajax.php', {username: jQuery('[name=login_name]').val(),
							password: jQuery('[name=login_pass]').val()},
							function(data) {
								if (date.success)
								{
									location.href=data.redirect;
								}
								else
								{
									jQuery('errorConsole').html(data.message).slideDown();	
								}
							}, 'json');
							return false;
		
		});
});
*/


 function validateFields(form){
	var fieldsValid = true;
	
	var searchText = document.getElementById('searchText');
	var searchBy = document.getElementById('searchBy');
	
	if (searchText.value.length < 3 || searchText.value == "Search for..."){
		 fieldsValid = false;
	}
	
	if (searchBy.value == "Search by...") {
		fieldsValid = false;
	}

	return fieldsValid;
 }